/*
 * @Description: 角色对应的权限名称
 * @Author: 'AgoniLay'
 * @Date: 2021-10-03 21:36:09
 * @LastEditTime: 2021-10-12 10:26:50
 * @FilePath: \subject-evaluation\src\utils\permission.js
 */
const roleToRoute = {
  3: [
    { name: '1-0' },
    { name: '1-0-1' },
    { name: '1-1' },
    { name: '1-1-1' },
    { name: '1-2' },
    { name: '1-2-1' },
    { name: '1-3' },
    { name: '1-3-1' },
    { name: '1-3-2' },
    { name: '1-3-3' },
    { name: '1-4' },
    { name: '1-4-1' },
    { name: '1-5' },
    { name: '1-5-1' },
    { name: '1-6' },
    { name: '1-6-1' },
    { name: '1-6-2' },
    { name: '2-1' },
    { name: '2-1-1' },
    { name: '2-2' },
    { name: '2-2-1' },
    { name: '2-2-2' },
    { name: '2-3' },
    { name: '2-3-1' },
    { name: '2-3-2' },
    { name: '3-1' },
    { name: '3-1-1' },
    { name: '3-2' },
    { name: '3-2-1' },
    { name: '3-3' },
    { name: '3-3-1' },
    { name: '3-3-2' },
    { name: '3-3-3' },
    { name: '3-4' },
    { name: '3-4-1' },
    { name: '4-1' },
    { name: '4-1-1' },
    { name: '4-2' },
    { name: '4-2-1' },
    { name: '4-3' },
    { name: '4-3-1' }
  ],
  2: [
    { name: 'School' },
    { name: 'SchoolUser' },
    { name: 'Simplify' },
    { name: '1-0' },
    { name: '1-0-1' },
    { name: '1-1' },
    { name: '1-1-1' },
    { name: '1-2' },
    { name: '1-2-1' },
    { name: '1-3' },
    { name: '1-3-1' },
    { name: '1-3-2' },
    { name: '1-3-3' },
    { name: '1-4' },
    { name: '1-4-1' },
    { name: '1-5' },
    { name: '1-5-1' },
    { name: '1-6' },
    { name: '1-6-1' },
    { name: '1-6-2' },
    { name: '2-1' },
    { name: '2-1-1' },
    { name: '2-2' },
    { name: '2-2-1' },
    { name: '2-2-2' },
    { name: '2-3' },
    { name: '2-3-1' },
    { name: '2-3-2' },
    { name: '3-1' },
    { name: '3-1-1' },
    { name: '3-2' },
    { name: '3-2-1' },
    { name: '3-3' },
    { name: '3-3-1' },
    { name: '3-3-2' },
    { name: '3-3-3' },
    { name: '3-4' },
    { name: '3-4-1' },
    { name: '4-1' },
    { name: '4-1-1' },
    { name: '4-2' },
    { name: '4-2-1' },
    { name: '4-3' },
    { name: '4-3-1' }
  ],
  1: [
    { name: 'Dictionary' },
    { name: 'System' },
    { name: 'SystemUser' },
    { name: 'Simplify' },
    { name: '1-0' },
    { name: '1-0-1' },
    { name: '1-1' },
    { name: '1-1-1' },
    { name: '1-2' },
    { name: '1-2-1' },
    { name: '1-3' },
    { name: '1-3-1' },
    { name: '1-3-2' },
    { name: '1-3-3' },
    { name: '1-4' },
    { name: '1-4-1' },
    { name: '1-5' },
    { name: '1-5-1' },
    { name: '1-6' },
    { name: '1-6-1' },
    { name: '1-6-2' },
    { name: '2-1' },
    { name: '2-1-1' },
    { name: '2-2' },
    { name: '2-2-1' },
    { name: '2-2-2' },
    { name: '2-3' },
    { name: '2-3-1' },
    { name: '2-3-2' },
    { name: '3-1' },
    { name: '3-1-1' },
    { name: '3-2' },
    { name: '3-2-1' },
    { name: '3-3' },
    { name: '3-3-1' },
    { name: '3-3-2' },
    { name: '3-3-3' },
    { name: '3-4' },
    { name: '3-4-1' },
    { name: '4-1' },
    { name: '4-1-1' },
    { name: '4-2' },
    { name: '4-2-1' },
    { name: '4-3' },
    { name: '4-3-1' }
  ]
}
/**
 * 过滤掉没有权限的路由
 * @param {String} role
 * @param {Array} routes
 */
export default function getMenuRoute (role, routes) {
  // console.log(role)
  const allowRoutesName = roleToRoute[role].map((item) => item.name)
  const resultRoutes = routes.filter((r) => {
    const obj = r
    if (allowRoutesName.indexOf(r.name) !== -1) {
      const { children } = obj
      obj.children = children.filter((c) => allowRoutesName.indexOf(c.name) !== -1)
      return true
    }
    return false
  })
  return resultRoutes
}
